const to = (promise, errMsg) => {
  if (typeof promise !== 'function' && !promise.then)
    throw new TypeError('not a promise')
  return promise
    .then(res => {
      return [res, undefined]
    })
    .catch(err => {
      if (errMsg) return [undefined, { ...errMsg, err }]
      return [undefined, err]
    })
}

export default to
